﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.Validation.Validators
{
	public abstract class OrStackedValidator : IValidator
	{
		/// <summary>
		/// Gets or sets the validators.
		/// </summary>
		/// <value>The validators.</value>
		protected IValidator[] Validators
		{
			get;
			set;
		}

		/// <summary>
		/// Validates the specified value.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <param name="against">The against.</param>
		/// <returns></returns>
		public virtual bool Validate(object value, object against)
		{
			var result = false;

			if (Validators != null)
			{
				foreach (var validator in this.Validators)
				{
					result |= validator.Validate(value, against);
				}
			}

			return result;
		}

		/// <summary>
		/// Validates the value against an array.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <param name="against">The against.</param>
		/// <returns></returns>
		public virtual bool ValidateArray(object value, params object[] against)
		{
			var result = false;

			if (Validators != null)
			{
				var i = 0;

				foreach (var validator in this.Validators)
				{
					result |= validator.Validate(value, against[i]);
					i++;
				}
			}

			return result;
		}
	}
}